﻿<div ng-controller="Supplier_NonstandardDiscountC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">仓库非标优惠特例</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation ">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="h4">{{$stateParams.name}}</span>
                        </div>
                        <div class="panel-body">
                            <div class="form-group " ng-repeat="item in data">
                                <label>{{item.Key.Name}}</label>
                                <input type="text" class="form-control" ng-model="item.Value" required/>
                            </div>

                        </div>
                        <footer class="panel-footer text-right bg-light lter">
                            <button type="button" class="btn btn-success" ng-disabled="form.$invalid" ng-click="Edit()">提交</button>
                            <button type="button" class="btn" ng-click="abolish()">取消</button>
                        </footer>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div>
        <select ng-options="item.Name for item in dataSups" ng-model="selectSup"></select>
        <input type="number" min="0" ng-model="selectNum" step="1" />
        <button type="button" ng-click="add()">添加</button>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
    .controller("Supplier_NonstandardDiscountC", function ($scope, $state, $http, $stateParams) {
       // $scope = $stateParams.name;
        //请求数据
        $http({
            url: "/api/NonstandardDiscount?depotId=" + $stateParams.id,
            method: "GET"
        })
            .then(function (res) {
                $scope.data = res.data;
                console.log($scope.data);
            })
            .then(function (error) {
                if (error) {
                    console.log("error");
                }
            });
        //添加下拉数据
        $http({
            url: "/api/Supplier/List?name=&page=1&rows=9999",
            method: "GET"
        })
          .then(function (res) {
              var supd = res.data.Data;
            
              $scope.dataSups =supd;
              console.log($scope.dataSups);

          })
          .then(function (error) {
              if (error) {
                  console.log("error");
              }
          });
        //
        $scope.add = function () {
            for (var i = 0; i < $scope.data.length; i++) {
                if ($scope.data[i].Key.Id == $scope.selectSup.Id) {
                    alert("已添加的优惠信息");
                    return;
                }
            }
            $scope.data.push({ Key: $scope.selectSup, Value: $scope.selectNum });
        };

        $scope.Edit= function() {
            $http.put("/api/NonstandardDiscount/Edit?depotId=" + $stateParams.id, $scope.data)
            .success(function() {
                    alert("修改成功");
                })
            ;
        }
    })
</script>